/**
 * @file sysapi.h
 * @brief T1 system call API
 *
 * @author tenly@witsi.cn
 * @date 2013-03-29
 * @version T1.API.01
 */
#ifndef T1_SYSAPI_H_
#define T1_SYSAPI_H_

#ifdef CONFIG_MMU
#define RX_EXPAPI(type, name)		\
__asm__( 							\
"	.section	.syscall,  \"ax\"\n" 	\
"	.set	noreorder\n" 			\
"	.set	noat\n" 				\
"	.globl	api_"#name"\n" 			\
"	.ent	api_"#name"\n" 			\
"api_"#name":\n" 					\
"	la		$9, _sp\n"	 			\
"	sw		$31, 0($9)\n" 			\
"	syscall\n" 						\
"	jal		"#name "\n" 			\
"	nop\n" 							\
"	j		api_ret2user\n" 		\
"	nop\n" 							\
"	.end		api_"#name"\n" 		\
"	.set	at\n" 					\
"	.set	reorder\n" 				\
); 									\
type name/*RX_API export here! Don't add anything after 'name'*/

#define RX_API_DEFINED(type, name)	\
__asm__( 							\
"	.section	.syscall,  \"ax\"\n" 	\
"	.set	noreorder\n" 			\
"	.set	noat\n" 				\
"#	.align	2\n"					\
"	.globl	api_"#name"\n" 			\
"	.ent	api_"#name"\n" 			\
"api_"#name":\n" 					\
"	la		$9, _sp\n"	 			\
"	sw		$31, 0($9)\n" 			\
"	syscall\n" 						\
"	jal		"#name "\n" 			\
"	nop\n" 							\
"	j		api_ret2user\n" 		\
"	nop\n" 							\
"	.end	api_"#name"\n" 			\
"	.set	at\n" 					\
"	.set	reorder\n" 				\
); 									\
type api_##name/*RX_API defined here! Don't add anything after 'name'*/
#define __GET_API(name)	api_##name/*RX_API used here! Don't add anything after 'name'*/
extern void user_mode(void);
extern void kernel_mode(void);
#else
#define __GET_API(name)		name/*RX_API used here! Don't add anything after 'name'*/
#define user_mode()		do{}while(0)
#define kernel_mode()	do{}while(0)
#endif

#endif /* T1_SYSAPI_H_ */
